1 Imports System.Collections.Generic
2 Imports System.Text
3 Imports System.IO
4 Imports System.Security.Cryptography
5 Public Class Encryption
6     Public Shared Function InverseByBase(st As String, MoveBase As Integer) As String
7         Dim SB As New StringBuilder()
8         
'st = ConvertToLetterDigit(st);
9         Dim c As Integer
10         Dim i As Integer =
0
11         While i < st.Length
12             If i + MoveBase > st.Length -
1 Then
13                 c = st.Length - i
14             Else
15                 c = MoveBase
16             End If
17             SB.Append(InverseString(st.Substring(i, c)))
18             i += MoveBase
19         End While
20         Return SB.ToString()
21     End Function
22
23     Public Shared Function InverseString(st As String) As String
24         Dim SB As New StringBuilder()
25         For i As Integer = st.Length -
1 To 0 Step -1
26             SB.Append(st(i))
27         Next
28         Return SB.ToString()
29     End Function
30
31     Public Shared Function ConvertToLetterDigit(st As String) As String
32         Dim SB As New StringBuilder()
33         For Each ch As Char In st
34             If Char.IsLetterOrDigit(ch) = False Then
35                 SB.Append(Convert.ToInt16(ch).ToString())
36             Else
37                 SB.Append(ch)
38             End If
39         Next
40         Return SB.ToString()
41     End Function
42
43     
''' <summary>
44     
''' moving all characters in string insert then into new index
45     
''' </summary>
46     
''' <param name="st">string to moving characters</param>
47     
''' <returns>moved characters string</returns>
48     Public Shared Function Boring(st As String) As String
49         Dim NewPlace As Integer
50         Dim ch As Char
51         For i As Integer =
0 To st.Length - 1
52             NewPlace = i * Convert.ToUInt16(st(i))
53             NewPlace = NewPlace Mod st.Length
54             ch = st(i)
55             st = st.Remove(i,
1)
56             st = st.Insert(NewPlace, ch.ToString())
57         Next
58         Return st
59     End Function
60
61     Public Shared Function MakePassword(st As String, Identifier As String) As String
62         If Identifier.Length <>
3 Then
63             Throw New ArgumentException(
"Identifier must be 3 character length")
64         End If
65
66         Dim num As Integer() = New Integer(
2) {}
67         num(
0) = Convert.ToInt32(Identifier(0).ToString(), 10)
68         num(
1) = Convert.ToInt32(Identifier(1).ToString(), 10)
69         num(
2) = Convert.ToInt32(Identifier(2).ToString(), 10)
70         st = Boring(st)
71         st = InverseByBase(st, num(
0))
72         st = InverseByBase(st, num(
1))
73         st = InverseByBase(st, num(
2))
74
75         Dim SB As New StringBuilder()
76         For Each ch As Char In st
77             SB.Append(ChangeChar(ch, num))
78         Next
79         Return SB.ToString()
80     End Function
81
82     Private Shared Function ChangeChar(ch As Char, EnCode As Integer()) As Char
83         ch = Char.ToUpper(ch)
84         If ch >=
"A"c AndAlso ch <= "H"c Then
85             Return Convert.ToChar(Convert.ToInt32(ch) +
2 * EnCode(0))
86         ElseIf ch >=
"I"c AndAlso ch <= "P"c Then
87             Return Convert.ToChar(Convert.ToInt32(ch) - EnCode(
2))
88         ElseIf ch >=
"Q"c AndAlso ch <= "Z"c Then
89             Return Convert.ToChar(Convert.ToInt32(ch) - EnCode(
1))
90         ElseIf ch >=
"0"c AndAlso ch <= "4"c Then
91             Return Convert.ToChar(Convert.ToInt32(ch) +
5)
92         ElseIf ch >=
"5"c AndAlso ch <= "9"c Then
93             Return Convert.ToChar(Convert.ToInt32(ch) -
5)
94         Else
95             Return
"0"c
96         End If
97     End Function
98 End Class


Gõ tìm kiếm nhanh...